function alertMSG(msg){
	closeloading();
	var alert_msg=  "<div class=\"am-modal am-modal-alert\" tabindex=\"-1\" id=\"alert_msg\" title=\"-1\">"
		+"<div class=\"am-modal-dialog\">"
			+"<div class=\"am-modal-bd\">"
				+"<h3 class=\"alertmsg_content\"> "+msg+"</h3>"	
			+" </div>"
				+"<div class=\"am-modal-footer\">"
					+"<span class=\"am-modal-btn\" onclick=\"closemsg()\">关闭</span>"
				+"</div>"
		+"</div>"
	+"</div>";
$("#parent_modal-loading").append(alert_msg);
$(".alertmsg_content").html(msg); 
var $modal = $('#alert_msg');
$modal.modal();

//$('#alert_msg').on('closed.modal.amui', function(){
//	$("#alert_msg").remove(); 
//	});
// Public_method.setMSG(msg);

	
}

/**添加等待加载代码**/
function loading(){
	
	var code= "<div class=\"am-modal am-modal-loading am-modal-no-btn\" tabindex=\"-1\" id=\"my-modal-loading\">"
					+"<div class=\"am-modal-dialog\">"
						+"<div class=\"am-modal-hd\">正在请求...</div>"
							+"<div class=\"am-modal-bd\">"
								+"<span class=\"am-icon-spinner am-icon-spin\"></span>"
								+"<div style=\"width: 70px; margin: auto auto; text-align: center; display: none ; \"  >"
									+"<a href=\"javascript: void(0)\" id = \"closeloading\"class=\"am-close am-close-spin\" data-am-modal-close>&times;</a>"
								+"<div>"
							+"</div>"
						+"</div>"
					+"</div>"
				+"</div>";
$("#parent_modal-loading").append(code);
	openloading();
	
}
/**打开等待提示等待框**/
function openloading(){
	var $modal = $('#my-modal-loading');
	$modal.modal();
}
/**关闭等待提示等待框**/
function closeloading(){
	//var $modal = $('#my-modal-loading');
	$("#closeloading").click()
	
	//$("#my-modal-loading").remove();
	// $modal.modal('close');
	// $("#parent_modal-loading").empty(); 
	 
	 
}

/**关闭提示模态框**/
function closemsg(){
var $modal = $('#alert_msg');
//$("#alert_msg").remove();
//$modal.modal('close');
//$("#parent_modal-loading").empty(); 

}
//获取当前登录了的用户名
function getLoginUserName(){

	var a = Public_method.getLoginUserName();
	return a;

}

//获取当前登录了的密码
function getLoginUserpassword(){

	var a = Public_method.getLoginUserpassword();
	return a;

}


//获取当前登录了的用户的资料
function getUserProfileByUserName(){
	
	var a = Public_method.getUserProfileByUserName(getLoginUserName());
	return a;
}

//获取当前用户角色
function getMyUserType(){
	
	return Public_method.getLoginUserType();
}

/**调用摄像机
 * x = 长比
 * y = 宽比
 * **/
function gotoPhoto( x,  y){
	PhotoFunction.setXY(x,y);
	PhotoFunction.gotoPhoto();

	
}
/**调用相册*
 * x = 长比
 * y = 宽比
 * */
function getPhoto( x,  y){
	PhotoFunction.setXY(x,y);
	PhotoFunction.getPhoto();
	
}

/**执行系统访问时使用定时器函数**/
function actuator(functionname){
	loading();//先打开等待框
	var timer = setTimeout(functionname,1000);
	
	

	
}

function exit(){
	
	Public_method.exit();
}




/*字符串转换json*/
function strToJson(str){ 
	var json = eval('(' + str + ')'); 
	return json; 
	} 



/*设置全局宽度*/
function set_w_h(w,h){
/*Public_method.set_w_h(w,h);*/

}
//根据参数名，获取上个acticity传过来的值
function getThisActivityParamate(pname){
	
	var p_value = Public_method.getThisActivityParamate(pname);
	return p_value;
}
function PageFinished(){

	var p_height = $(window).height();
	var p_width = $(window).width();
	
	if($(window).width()>0){
		
		set_w_h($(window).width(),$(window).height());
	}
	if(p_width <= 0){
		var wh_json = strToJson(Public_method.get_w_h());
		//
		if(wh_json!=""){
			for(var i=0,l=wh_json.length;i<l;i++){
				for(var key in wh_json[i]){
//					alert(key+':'+wh_json[i][key]);
					if(key == "height"){
						p_height = wh_json[i][key];
//						alert(p_height+"p_height");
						}
					if(key == "width"){
						p_width = wh_json[i][key];
//						alert(p_width+"p_width");
					}
				}
		    }  
		}
		
	}
	
	
	$('#parent').css('height',p_height);
	$('#parent').css('width',p_width);
	init(p_width ,p_height);
	
	var msg = Public_method.getMSG();
	if(msg!=null){
			alertMSG(msg);
			Public_method.setMSG("");
	}
	//权限
	Permission();
	closeloading();
};

function sysmsgGather(){
	
	MsgFunction.sysmsgGather();
}



//权限
function Permission(){
	var usertype = getMyUserType()+"";
	
	//查找所有开头的权限
	$("[class^='Pa_']").each(function(){
	
		var isremove = 1;
		var pe = $(this).attr("class");
	
//		for(var i =3 ;i<pe.length;i++){
//			var ii= i+1;
//			if(ii>pe.length){
//				ii=i;
//			}
//			var p = pe.slice(i,i+1);
//			if(p == usertype){
//				isremove =0;
//			}
//			
//		}
		var ispe= "_"+usertype;
		
		//如果不是自己的权限删除掉
		if(pe.indexOf(ispe)<0){
			$(this).remove();
		}
	});
}



$(document).ready(function(){
	var code= 	"<div id =\"parent_modal-loading\"> </div>";
				$("#parent").append(code);
	loading();
	
	
}); 